package cn.edu.hhtc.stsystem.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.hhtc.stsystem.Exception.ServiceException;
import cn.edu.hhtc.stsystem.dao.PrimaryMaterialDao;
import cn.edu.hhtc.stsystem.entity.PrimaryMaterialEntity;
import cn.edu.hhtc.stsystem.entity.form.PrimaryMaterialEntityForm;

@Service("primaryMaterialService")
@Transactional(rollbackFor=Exception.class)
public class PrimaryMaterialServiceImpl implements PrimaryMaterialService {
	@Autowired
	private PrimaryMaterialDao primaryMaterialDao;

	@Override
	public void addPrimaryMaterial(PrimaryMaterialEntityForm form) throws ServiceException {
		try {
			PrimaryMaterialEntity entity  = new PrimaryMaterialEntity(form.getPmName(),form.getPmPrice(),
					form.getPmCategory(),form.getPmUnit(),form.getPmStaple(),form.getPmOrigin());
			primaryMaterialDao.save(entity);
		} catch(Exception e) {
			throw new ServiceException(e);
		}
		
	}

}
